package com.leenmvc.core.utils.socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.channels.SocketChannel;

/**
 * Socket主题接口， SocketClient中可以传递SocketTheme用于处理不同的主题
 */
public interface SocketTheme {

    final static Logger logger = LoggerFactory.getLogger(SocketTheme.class);

    /**
     * @param socketMessage
     * @param socketClient
     * @param sc
     */
    default void shutdown_client(SocketMessage socketMessage, SocketClient socketClient, SocketChannel sc) {
        logger.info("收到关闭主题，客户端" + socketMessage.getTo() + "将要被关闭");
        try {
            sc.close();
            socketClient.getClient().close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    /**
     *
     * @param socketMessage
     * @param socketClient
     * @param sc
     */
    default void register_info(SocketMessage socketMessage, SocketClient socketClient, SocketChannel sc) {
        logger.info("【SOCKET-THEME】收到注册主题，客户端" + socketMessage.getClientId() + "将要注册！");
    }

}
